/**
 * 
 */
package com.efast.cafe.util.jxl;

import jxl.CellType;
import jxl.format.Border;
import jxl.format.Colour;
import jxl.format.VerticalAlignment;
import jxl.write.Alignment;
import jxl.write.BorderLineStyle;
import jxl.write.NumberFormat;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WriteException;

import org.springframework.stereotype.Component;

/**
 * @author Wangjianglin
 * FUNCTION : 类的主要功能描述
 *======================================================
 * CHANGE HISTORY
 *
 * YYMMDD    WHO       Description
 * -----------------------------------------------------
 * 2012-12-10   Name     	首次创建
 *======================================================
 */
@Component  
public class DefaultDataCellFormat implements IDataCellFormat{  
  
    @Override  
    public WritableCellFormat getDataCellFormat(CellType type) {  
        // TODO Auto-generated method stub  
          WritableCellFormat wcf = null;     
           try {     
               //字体样式     
               if(type == CellType.NUMBER || type == CellType.NUMBER_FORMULA){//数字     
                  NumberFormat nf = new NumberFormat("#.00");     
                  wcf = new WritableCellFormat(nf);      
               }else if(type == CellType.DATE || type == CellType.DATE_FORMULA){//日期     
                   jxl.write.DateFormat df = new jxl.write.DateFormat("yyyy-MM-dd hh:mm");      
                   wcf = new jxl.write.WritableCellFormat(df);      
               }else{     
                   WritableFont wf = new WritableFont(WritableFont.TIMES,10, WritableFont.NO_BOLD,false);//最后一个为是否italic     
                   wcf = new WritableCellFormat(wf);     
               }     
               //对齐方式     
               wcf.setAlignment(Alignment.CENTRE);     
               wcf.setVerticalAlignment(VerticalAlignment.CENTRE);     
               //边框     
               wcf.setBorder(Border.LEFT,BorderLineStyle.THIN);     
               wcf.setBorder(Border.BOTTOM,BorderLineStyle.THIN);     
               wcf.setBorder(Border.RIGHT,BorderLineStyle.THIN);     
               //背景色     
               wcf.setBackground(Colour.WHITE);     
                    
               wcf.setWrap(true);//自动换行     
                    
           } catch (WriteException e) {     
            e.printStackTrace();     
           }     
           return wcf;      
    }  
  
}  

